import random, re, time


def random_char(upper=True):
    if upper:
        return chr(random.randint(ord('A'), ord('Z')))
    else:
        return chr(random.randint(ord('a'), ord('z')))


def random_str(length=10, upper=True):
    s = ''
    for i in range(length):
        s += random_char(upper)
    return s


def random_str2(length=10):
    s = ''
    for i in range(length):
        s += random_char(random.choice([True, False]))
    return s


def is_id_card(id_card):
    result = re.match('^[1-9]\d{5}(19|20)\d{2}((0[1-9])|(1[0-2]))([0-2][1-9]|10|20|30|31)\d{3}[X\d]$', id_card)
    return result is not None


def get_time():
    return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())